﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace OnlineEducation.Helpers
{
    public  class OrderHelper
    {
         
        private OrderHelper() { }

        private static readonly object Locker = new object();

        private static int _sn = 0;
        public static string GenerateOrderID(int Id)
        {
            lock (Locker)  //lock 关键字可确保当一个线程位于代码的临界区时，另一个线程不会进入该临界区。
            {
                if (_sn == int.MaxValue)
                {
                    _sn = 0;
                }
                else
                {
                    _sn++;
                }

                Thread.Sleep(100);

                return string.Format("{0:D4}", Id) + DateTime.Now.ToString("yyMMddHHmmss") + _sn.ToString().PadLeft(2, '0');
            }

           


        }

    
 
    }
}
